#include "common.hpp"

int main()
{
    std::cout << "wait write" << std::endl;
    int rfd = open(NAMED_PIPE, O_RDONLY);
    std::cout << "wait finish" << std::endl;
    if (rfd < 0)
    {
        exit(0);
    }
    while (1)
    {
        char buffer[1024];
        ssize_t n = read(rfd, buffer, sizeof(buffer) - 1);
        if (n > 0)
        {
            buffer[n - 1] = 0;
            std::cout << "receive message: " << buffer << std::endl;
        }
        else if (n == 0)
        {
            break;
        }
        else
        {
            break;
        }
    }
    close(rfd);
}